package com.chixing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chixing.mapper.LikesMapper;
import com.chixing.pojo.Likes;
import com.chixing.service.ILikesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author pyc
 * @since 2022-11-07
 */
@Service
public class LikesServiceImpl extends ServiceImpl<LikesMapper, Likes> implements ILikesService {

    @Autowired
    private LikesMapper likesMapper;


    @Override
    public void addlikes(Likes likes) {
        Integer uId = likes.getUserId();
        Integer eId = likes.getEvaluationId();
        QueryWrapper<Likes> wrapper = new QueryWrapper<>();
        wrapper.eq("evaluation_id",eId);
        wrapper.eq("user_id",uId);
        List<Likes> likesList = likesMapper.selectList(wrapper);
        if (likesList.size()==0)
            likesMapper.insert(likes);
    }
}
